from django.urls import path
from django.shortcuts import redirect
from . import views
from . import friend_views
from . import group_views

app_name = 'social'

urlpatterns = [
    # 关注
    path('follow/<int:user_id>/', views.follow_user, name='follow_user'),
    path('unfollow/<int:user_id>/', views.unfollow_user, name='unfollow_user'),
    path('followers/', views.followers_list, name='followers_list'),
    path('following/', views.following_list, name='following_list'),
    path('users/', views.user_list, name='user_list'),
    
    # 聊天主页面（新的组合布局）
    path('chat/', views.chat_main, name='chat_main'),
    path('chat/content/<int:conversation_id>/', views.chat_content, name='chat_content'),
    path('conversations/start/<int:user_id>/', views.start_conversation, name='start_conversation'),
    path('conversations/<int:conversation_id>/delete/', views.delete_conversation, name='delete_conversation'),
    
    # 会话和私信API（保留用于发送消息等操作）
    path('conversations/<int:conversation_id>/send/', views.send_message_api, name='send_message_api'),
    path('conversations/<int:conversation_id>/read/', views.mark_messages_read, name='mark_messages_read'),
    path('conversations/<int:conversation_id>/messages/', views.get_conversation_messages, name='get_conversation_messages'),
    path('conversations/list/', views.get_conversations_list, name='get_conversations_list'),
    
    # 好友功能
    path('friends/search/', friend_views.search_users, name='search_users'),
    path('friends/request/send/<int:user_id>/', friend_views.send_friend_request, name='send_friend_request'),
    path('friends/request/accept/<int:request_id>/', friend_views.accept_friend_request, name='accept_friend_request'),
    path('friends/request/reject/<int:request_id>/', friend_views.reject_friend_request, name='reject_friend_request'),
    path('friends/remove/<int:user_id>/', friend_views.remove_friend, name='remove_friend'),
    path('friends/list/', friend_views.get_friends_list, name='get_friends_list'),
    path('friends/requests/', friend_views.get_friend_requests, name='get_friend_requests'),
    path('friends/profile/<int:user_id>/', friend_views.friend_profile, name='friend_profile'),
    
    # 群组功能
    path('groups/create/', group_views.create_group, name='create_group'),
    path('groups/list/', group_views.get_groups_list, name='get_groups_list'),
    path('groups/<int:group_id>/', group_views.get_group_detail, name='get_group_detail'),
    path('groups/<int:group_id>/messages/', group_views.get_group_messages, name='get_group_messages'),
    path('groups/<int:group_id>/send/', group_views.send_group_message, name='send_group_message'),
    path('groups/<int:group_id>/update/', group_views.update_group, name='update_group'),
    path('groups/<int:group_id>/avatar/', group_views.update_group_avatar, name='update_group_avatar'),
    path('groups/<int:group_id>/members/add/', group_views.add_group_member, name='add_group_member'),
    path('groups/<int:group_id>/members/remove/<int:user_id>/', group_views.remove_group_member, name='remove_group_member'),
    path('groups/<int:group_id>/leave/', group_views.leave_group, name='leave_group'),
    path('groups/<int:group_id>/dissolve/', group_views.dissolve_group, name='dissolve_group'),
    
    # 旧的URL重定向到新页面
    path('conversations/', lambda request: redirect('social:chat_main'), name='conversation_list'),
    path('conversations/<int:conversation_id>/', lambda request, conversation_id: redirect('social:chat_main'), name='conversation_detail'),

    #系统通知
    path('notifications/list/', views.notifications_list, name='notifications_list'),
    path('notifications/<int:notification_id>/mark-read/', views.mark_notification_read, name='mark_notification_read'),
    path('notifications/mark-all-read/', views.mark_all_notifications_read, name='mark_all_notifications_read'),
    path('notifications/delete-all/', views.delete_all_notifications, name='delete_all_notifications'),
    
    # 未读计数API
    path('api/unread-counts/', views.get_unread_counts, name='get_unread_counts'),

]
